import axios from 'axios'
let baseUrl = 'http://localhost:8088/'
/* if (process.env.NODE_ENV === 'development') {
  // this.fileUploadUrl=''
} else {
  baseUrl = 'https://www.wsblob.com/wsblob-server/'
} */
/**
 * HTTP请求封装
 */
// alert(baseUrl)
let http = axios.create({
  baseURL: baseUrl,
  withCredentials: false,
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  }
})
function apiAxios (method, url, params, response) {
  http({
    method: method,
    url: url,
    data: method === 'POST' || method === 'PUT' ? params : null,
    params: method === 'GET' || method === 'DELETE' ? params : null
  }).then(function (res) {
    console.log(res)
    if (res.data.code === '200') {
      response(res)
    } else if (res.data.code === '403') {
      response(res)
    } else {
      response(res)
    }
  }).catch(function (err) {
    response(err)
  })
}

export default {
  get: function (url, params, response) {
    return apiAxios('GET', url, params, response)
  },
  post: function (url, params, response) {
    return apiAxios('POST', url, params, response)
  },
  put: function (url, params, response) {
    return apiAxios('PUT', url, params, response)
  },
  delete: function (url, params, response) {
    return apiAxios('DELETE', url, params, response)
  }
}
